$(document).ready(function() {
    $('#submit_eleve').click(function() {
		var validation = $("#createEleveForm").validationEngine('validate');
		if (validation) {
			$.ajax({
					type: "POST",
					url: "adapter/eleveInscription.php",
					data: $('form#createEleveForm').serialize(),
					beforeSend: function (){
						$("#loading").show();
					$("#submit_btn").hide();
					}
					}).done(function(msg) {
						$("#loading").hide();
						$("#submit_btn").show();
						if (msg == 0) {
							$("#error").show();
						}
						else {
							console.log(msg);
							var idParent = msg;
							$('#createEleve').bPopup().close();
							eleveSearch (idParent);
						}
				
			});
            console.log(validation + " => Formulaire validé !!");
		}
                else {
                    console.log(validation + " => Formulaire non validé !!");
                }
    });
	
	function eleveSearch (idParent) {
		$.ajax({
			type: "POST",
			url: "adapter/eleveSearch.php",
			data: {"idParent":idParent},
			beforeSend: function (){
				$("#loading").show();
				$("#" + idParent).html("");
			}
			}).done(function(msg) {
				$("#loading").hide();
				$("#" + idParent).append(msg);
		});
	}
});